home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / appletalk.idb / usr / etc / appletalk / ksd_restart.z / ksd_restart
Text File  |  2002-03-07  |  3KB  |  129 lines

  1. #!/bin/csh -f
  2. #
  3. #  @(#)ksd_restart    10.3  00/02/01     Xinet, Inc.
  4. #
  5. # ksd_restart - halt/restart AppleShare
  6. # usage: ksd_retart [servername]
  7. #
  8. #
  9. set BIN=/usr/etc/appletalk
  10. set path=(${BIN} /bin /etc /usr/{bin,ucb,bsd} /usr/etc .)
  11. set ADM=/var/adm/appletalk
  12. set SERVICES=${BIN}/services
  13.  
  14. if (-x /bin/id) then
  15.     if (`/bin/id | grep -c uid=0` > 0) then
  16.         set me=root
  17.     else
  18.         set me=notroot
  19.     endif
  20. else
  21.     set me=`whoami`
  22. endif
  23. if ("$me" != root) then 
  24.     echo "You must have root privileges to run this script"
  25.     exit 1
  26. endif
  27.  
  28. if ("$1" == "") then
  29.     set pid=`grep AFPServer ${ADM}/nbpreg_pids | tail -1 | awk '{print $1}'`
  30.     set name=`grep AFPServer ${ADM}/nbpreg_pids | tail -1 | awk '{print $2}'`
  31. else 
  32.     set pid=`grep "$1" ${ADM}/nbpreg_pids | grep AFPServer | tail -1 | awk '{print $ 1}'`
  33.     set name="$1"
  34. endif
  35.  
  36. if ("$pid" == "0" || "$pid" == "") then
  37.     set pid=`grep XinetServer ${ADM}/nbpreg_pids | tail -1 | awk '{print $1}'`
  38. endif
  39.  
  40. if ("$pid" == "0" || "$pid" == "") then
  41.     if ("$1" == "") then
  42.         echo "I don't see a AppleShare server running on this machine"
  43.     else
  44.         echo "I don't see AppleShare server $1 running on this machine"
  45.     endif
  46.     goto restart
  47. endif
  48.  
  49. repprint:
  50. echo -n "Do you really want to halt the AppleShare daemon? "
  51. set resp=$<
  52. if ("$resp" =~ [Nn]*) then
  53.     echo "Leaving AppleShare running."
  54.     exit 1
  55. else if ("$resp" !~ [Yy]*) then
  56.     echo Please answer \"yes\" or \"no\":
  57.     goto repprint
  58. endif
  59. endif
  60.  
  61. echo -n "Do you want to give the users time to disconnect[y]? "
  62. set resp=$<
  63. if ("$resp" !~ [Nn]*) then
  64. mins:
  65.     echo -n "How many minutes do you want to wait[2]: " 
  66.     set mins=$<
  67.     if ($mins == "") then
  68.         set mins = "2"
  69.     endif
  70.     @ secs = $mins * 60
  71.     if ($mins != "0" && $secs == "0") then
  72.         echo "Invalid minutes $mins, try again."
  73.         goto mins
  74.     endif
  75.     
  76.     echo -n "Do you want customize the logout message[n]? "
  77.     set resp=$<
  78.     if ("$resp" =~ [Yy]*) then
  79.         echo "Enter the logout message now, followed by a ^D"    
  80.         cat > /tmp/ksmessage.$$
  81.     else
  82.         echo "AppleShare being shut down" > /tmp/ksmessage.$$
  83.     endif
  84.     while ($mins != "0")
  85.         rm -f ${ADM}/msg
  86.         echo "    $mins" > ${ADM}/msg
  87.         cat /tmp/ksmessage.$$ >> ${ADM}/msg
  88.         chmod 644 ${ADM}/msg
  89.         kill -USR2 $pid
  90.                 echo "Server will shut down in $mins minute(s)"
  91.                 @ mins--
  92.         sleep 60
  93.         end
  94.     rm -f ${ADM}/msg
  95.     rm -f /tmp/ksmessage.$$
  96. endif
  97.  
  98. echo "Killing the daemon..."
  99. set res=`kill $pid`
  100. if ($status) then
  101.     echo "Error killing daemon: $res"
  102.     echo "Attempting to remove registered name"
  103.     nbpremove -T AFPServer -O $name 
  104.     if (-r ${ADM}/serial) then
  105.         set s=`cat ${ADM}/serial`
  106.         if ("$s" != "") nbpremove -T XinetServer -O $s
  107.     endif
  108. endif
  109.  
  110. sleep 5
  111. set newpid=`grep AFPServer ${ADM}/nbpreg_pids | tail -1 | awk '{print $1}'`
  112.  
  113. if ("$newpid" == "$pid") then 
  114.     echo "ERROR: The daemon did not die."
  115.     exit 1
  116. endif
  117.  
  118. restart:
  119.  
  120. set noglob
  121. set line=`grep ksd ${SERVICES} | tail -1`
  122.  
  123. echo -n "Do you want to re-start the AppleShare daemon[y]? "
  124. set resp=$<
  125. if ("$resp" !~ [nN]*) then
  126.     echo "Restarting AppleShare $line"
  127.     echo $line | csh -fe
  128. endif
  129.